package laborhazi;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class DataInput extends JFrame{
	
	private Game game = null;
	private JFrame me = null;
	/**
	 * Mandatory serial version UID
	 */
	private static final long serialVersionUID = 1L;
	public DataInput(Game newGame) {
		super("Highscore entry", null);
		game = newGame;
		me = this; //help access the instance from inner class
		int width, height; // width and height of window
		width = 240;
		height = 80;
		
		JPanel contentPane = new JPanel(new GridLayout(2,1));
		final JTextField textField = new JTextField();
		textField.setSize(15,1); //create new text field in size
		JLabel label = new JLabel("Give your name here: ");
		label.setSize(27, 1); //create new label in size
		textField.addActionListener( new ActionListener( ){ //on ENTER
			public void actionPerformed( ActionEvent ae ){
				game.setName( new String (textField.getText( )) );
				game.score.add();
				me.dispose();
			}
		});
		/* do nothing on close the window */
		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		/* add text field and label */
		contentPane.add(label);
		contentPane.add(textField);
		/* set window visible*/	
		contentPane.setOpaque(true);
		this.setContentPane(contentPane);
		this.setSize(width, height);
		setVisible(true);
	}
	
	
	
}
